package org.skavookie.linalg

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 9/20/11
 * Time: 7:36 AM
 * To change this template use File | Settings | File Templates.
 */

case class Matrix(matrix: Seq[Double]*) {

  lazy val col: Int = matrix(0) length
  lazy val row: Int = matrix length
  lazy val flatMatrix: Seq[Double] = matrix flatten

  lazy val transpose: Matrix =
    Matrix((for (i <- 0 until col) yield
              for (xs <- matrix) yield xs(i)): _*)

  def *(om: Matrix): Matrix = {
    val ysst = om.transpose.matrix
    Matrix(
      (for (xs <- matrix) yield
         for (yst <- ysst) yield (Vec(xs: _*) dot Vec(yst: _*))): _*)
  }

  def *(v: Vec): Vec =
    Vec((for (xs <- matrix) yield (v dot Vec(xs: _*))): _*)

}
